<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JsCss Demo</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            /* 明亮主题 */
            --primary-color: #6366f1;
            --secondary-color: #4f46e5;
            --background-color: #f8fafc;
            --text-color: #1e293b;
            --border-color: #e2e8f0;
            --success-color: #22c55e;
            --warning-color: #f59e0b;
            --card-bg: #ffffff;
        }

        .dark-theme {
            /* 暗黑主题 */
            --primary-color: #4338ca;
            --secondary-color: #3730a3;
            --background-color: #0f172a;
            --text-color: #f8fafc;
            --border-color: #1e293b;
            --success-color: #16a34a;
            --warning-color: #d97706;
            --card-bg: #1e293b;
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'Segoe UI', system-ui, sans-serif;
            background-color: var(--background-color);
            color: var(--text-color);
            line-height: 1.6;
            transition: all 0.3s ease;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 280px;
            height: 100vh;
            position: fixed;
            top: 0;
            left: -280px;
            background: var(--card-bg);
            box-shadow: 4px 0 15px rgba(0,0,0,0.1);
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            z-index: 1000;
            padding: 1.5rem;
        }

        .sidebar.open {
            left: 0;
        }

        .sidebar-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 2rem;
        }

        .sidebar-nav {
            list-style: none;
        }

        .nav-item {
            margin-bottom: 0.75rem;
        }

        .nav-link {
            display: flex;
            align-items: center;
            padding: 0.75rem 1rem;
            border-radius: 8px;
            color: var(--text-color);
            text-decoration: none;
            transition: all 0.2s ease;
        }

        .nav-link:hover {
            background: var(--primary-color);
            color: white;
        }

        .nav-link i {
            margin-right: 1rem;
            width: 24px;
            text-align: center;
        }

        /* 主内容区 */
        .main-content {
            margin-left: 0;
            transition: margin-left 0.3s ease;
            min-height: 100vh;
        }

        /* 头部样式 */
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 1rem 2rem;
            background: var(--card-bg);
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            position: sticky;
            top: 0;
            z-index: 999;
        }

        /* 卡片布局 */
        .dashboard {
            padding: 2rem;
            display: grid;
            gap: 1.5rem;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
        }

        .card {
            background: var(--card-bg);
            border: 1px solid var(--border-color);
            border-radius: 16px;
            padding: 1.5rem;
            transition: transform 0.3s ease;
        }

        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 20px rgba(0,0,0,0.1);
        }

        .card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1rem;
        }

        .card-title {
            font-size: 1.25rem;
            font-weight: 600;
        }

        /* 按钮样式 */
        .btn {
            padding: 0.5rem 1rem;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.2s ease;
            display: inline-flex;
            align-items: center;
            gap: 0.5rem;
        }

        .btn-primary {
            background: var(--primary-color);
            color: white;
        }

        .btn-primary:hover {
            background: var(--secondary-color);
        }

        .btn-icon {
            padding: 0.5rem;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            justify-content: center;
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .dashboard {
                grid-template-columns: 1fr;
                padding: 1rem;
            }

            .header {
                padding: 1rem;
            }

            .sidebar {
                width: 100%;
                left: -100%;
            }
        }

        /* 遮罩层 */
        .overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.4);
            z-index: 999;
            display: none;
        }

        .overlay.active {
            display: block;
        }

        /* 动画效果 */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .animate-fade {
            animation: fadeIn 0.5s ease-out;
        }
    </style>
</head>
<body>
    <div class="sidebar animate-fade">
        <div class="sidebar-header">
            <h2>管理菜单</h2>
            <button class="btn btn-icon btn-primary" id="closeSidebar">
                <i class="fas fa-times"></i>
            </button>
        </div>
        <nav>
            <ul class="sidebar-nav">
                <li class="nav-item">
                    <a href="#" class="nav-link">
                        <i class="fas fa-home"></i>
                        仪表盘
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#" class="nav-link">
                        <i class="fas fa-chart-bar"></i>
                        数据分析
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#" class="nav-link">
                        <i class="fas fa-users"></i>
                        用户管理
                    </a>
                </li>
                <li class="nav-item">
                    <a href="#" class="nav-link">
                        <i class="fas fa-cog"></i>
                        系统设置
                    </a>
                </li>
            </ul>
        </nav>
    </div>

    <div class="overlay" id="overlay"></div>

    <div class="main-content">
        <header class="header animate-fade">
            <button class="btn btn-primary" id="menuToggle">
                <i class="fas fa-bars"></i>
                打开菜单
            </button>
            <div class="header-actions">
                <button class="btn btn-icon btn-primary" id="themeToggle">
                    <i class="fas fa-moon"></i>
                </button>
            </div>
        </header>

        <main class="dashboard">
            <div class="card animate-fade">
                <div class="card-header">
                    <h3 class="card-title">数据概览</h3>
                    <i class="fas fa-chart-line"></i>
                </div>
                <p>本周活跃用户：1,234</p>
                <p>新增订单：356</p>
            </div>

            <div class="card animate-fade">
                <div class="card-header">
                    <h3 class="card-title">最新动态</h3>
                    <i class="fas fa-bell"></i>
                </div>
                <ul>
                    <li>新用户注册：张三</li>
                    <li>订单 #1234 已完成</li>
                    <li>系统更新至 v2.1</li>
                </ul>
            </div>

            <div class="card animate-fade">
                <div class="card-header">
                    <h3 class="card-title">快捷操作</h3>
                    <i class="fas fa-bolt"></i>
                </div>
                <button class="btn btn-primary">
                    <i class="fas fa-plus"></i>
                    新建项目
                </button>
                <button class="btn btn-primary">
                    <i class="fas fa-upload"></i>
                    上传文件
                </button>
            </div>
        </main>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            // 主题切换
            const themeToggle = document.getElementById('themeToggle');
            const setTheme = (isDark) => {
                document.documentElement.classList.toggle('dark-theme', isDark);
                themeToggle.innerHTML = isDark ? 
                    '<i class="fas fa-sun"></i>' : 
                    '<i class="fas fa-moon"></i>';
                localStorage.setItem('theme', isDark ? 'dark' : 'light');
            };

            const savedTheme = localStorage.getItem('theme') || 
                (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
            setTheme(savedTheme === 'dark');

            themeToggle.addEventListener('click', () => {
                const isDark = !document.documentElement.classList.contains('dark-theme');
                setTheme(isDark);
            });

            // 侧边栏控制
            const sidebar = document.querySelector('.sidebar');
            const overlay = document.getElementById('overlay');
            const menuToggle = document.getElementById('menuToggle');
            const closeSidebar = document.getElementById('closeSidebar');

            const toggleSidebar = (show) => {
                sidebar.classList.toggle('open', show);
                overlay.classList.toggle('active', show);
                document.body.style.overflow = show ? 'hidden' : '';
            };

            menuToggle.addEventListener('click', () => toggleSidebar(true));
            closeSidebar.addEventListener('click', () => toggleSidebar(false));
            overlay.addEventListener('click', () => toggleSidebar(false));

            // 关闭侧边栏当点击外部或按ESC
            document.addEventListener('keydown', (e) => {
                if (e.key === 'Escape' && sidebar.classList.contains('open')) {
                    toggleSidebar(false);
                }
            });

            // 响应式自动关闭侧边栏
            window.addEventListener('resize', () => {
                if (window.innerWidth >= 768 && sidebar.classList.contains('open')) {
                    toggleSidebar(false);
                }
            });
        });
    </script>
</body>
</html>